/**
 * 匠言知识付费v2.0.0
 * Author: 山西匠言网络科技有限公司
 * 这不是一个免费软件，它受限于许可条款，你可以访问https://www.zsfzxkc.cn/获取更多详细信息。
 * This is not a free software, it under the license terms, you can visit https://www.zsffzxkc.cn/ get more details.
 */
<template>
	<view class="container">
		<jy-quick-btns></jy-quick-btns>
		<!-- 背景图片 -->
		<view class="beijing">
			<image :src="course.thumb" mode="aspectFill"></image>
		</view>

		<!-- 课程名称 -->
		<view class="course-name">
			<text>{{course.name}}</text>
			<view>
				<view class="jianjie">
					<text>{{course.jianjie}}</text>
				</view>
			</view>
			<view class="price">
				<text>报名价：<text>￥{{course.price}}</text></text>
				<text>原价：￥{{course.oldprice}}</text>
			</view>
		</view>
		
		
		
		<!-- 课程介绍 -->
		<view class="kcjs">
			<text class="kcjs-title">课程介绍</text>
			<view class="kcjj">
				<jyf-parser :html="introduce" ></jyf-parser>
			</view>
		</view>
		
		
		<!-- 立即报名 -->
		<view class="ljbm" v-if="action=='' ">
			<text>￥{{course.price}}</text>
			<text @click="pay">提交订单</text>
		</view>
		<view class="ljbm" v-if="action=='credit' ">
			<text>{{creditinfo.credit}}积分</text>
			<text @click="exchange">立即兑换</text>
		</view>
		<view class="ljbm" v-if="action=='seckill' ">
			<text>秒杀价 ￥{{seckillinfo.price}}</text>
			<text @click="seckill">立即秒杀</text>
		</view>
		<view class="ljbm" v-if="action=='pintuan' ">
			<text>拼团价 ￥{{pintuaninfo.price}}</text>
			<text @click="pintuan">开始拼团</text>
		</view>
	</view>
</template>

<script>
	import jyfParser from "@/components/jyf-parser/jyf-parser";
	export default {
		components:{
			jyfParser
		},
		data() {
			return {
				HOST_URL:uni.HOST_URL,
				course:[],
				introduce:'',
				action:'',
				creditinfo:{},
				seckillinfo:{},
				pintuaninfo:{}
			};
		},
		onShareAppMessage(res) {
			let path = getCurrentPages()
			let path_share = path[0].$page.fullPath
			let path_title = path[0].data.title
			let userinfo = uni.getStorageSync('userinfo')
			let base_set = uni.getStorageSync('base_set')
			if(userinfo.uid=='' || !userinfo.uid){
				uni.navigateTo({
					url:'../login/login'
				})
				return {
					title: '请先登录后再分享给好友',
					path: ''
				}
			}else{
				if (res.from === 'button') {
					
				}
				return {
					title: base_set.title,
					path: `${path_share}?pid=${userinfo.uid}`
				}
			}
		},
		onLoad(e) {
			var id=e.id
			if(e.action){
				this.action=e.action
				if(e.action=='credit'){
					this.get_creditinfo(id,'pxb')
				}else if(e.action=='seckill'){
					this.get_seckillinfo(id,'pxb')
				}else if(e.action=='pintuan'){
					this.get_pintuaninfo(id,'pxb')
				}
			}
			this.get_detail(id)
		},
		methods:{
			pay(){
				uni.navigateTo({
					url:'/pages/confirm-order-form/confirm-order-form?id='+this.course.id+'&goodstype=pxcourse'
				})
			},
			exchange(){
				uni.navigateTo({
					url:'/pages/confirm-order-form/confirm-order-form?id='+this.course.id+'&goodstype=pxcourse'+'&action=credit'
				})
			},
			seckill(){
				uni.navigateTo({
					url:'/pages/confirm-order-form/confirm-order-form?id='+this.course.id+'&goodstype=pxcourse'+'&action=seckill'
				})
			},
			pintuan(){
				uni.navigateTo({
					url:'/pages/confirm-order-form/confirm-order-form?id='+this.course.id+'&goodstype=pxcourse'+'&action=pintuan'
				})
			},
			get_detail(id){
				const BASE_URL = uni.BASE_URL
				uni.request({
					url: BASE_URL+'index/pxb/coursedetail',
					data: {
						id:id
					},
					method:'POST',
					success:(res) =>{
						console.log(res.data);
						this.course=res.data.data
						this.introduce=res.data.data.introduce
					},
					fail:(res)=> {
						console.log(res.data);
					}
				});
			},
			get_seckillinfo(id,goodstype){
				const BASE_URL = uni.BASE_URL
				uni.request({
					url: BASE_URL+'index/seckill/seckillinfo',
					data: {
						id:id,
						goodstype:goodstype
					},
					method:'POST',
					success:(res) =>{
						console.log(res.data)
						this.seckillinfo=res.data.data
					},
					fail:(res)=> {
						console.log(res.data);
					}
				});
			},
			get_pintuaninfo(id,goodstype){
				const BASE_URL = uni.BASE_URL
				uni.request({
					url: BASE_URL+'index/pintuan/pintuaninfo',
					data: {
						id:id,
						goodstype:goodstype
					},
					method:'POST',
					success:(res) =>{
						console.log(res.data)
						this.pintuaninfo=res.data.data
					},
					fail:(res)=> {
						console.log(res.data);
					}
				});
			},
			get_creditinfo(id,goodstype){
				const BASE_URL = uni.BASE_URL
				uni.request({
					url: BASE_URL+'index/credit/creditinfo',
					data: {
						id:id,
						goodstype:goodstype
					},
					method:'POST',
					success:(res) =>{
						console.log(res.data)
						this.creditinfo=res.data.data
					},
					fail:(res)=> {
						console.log(res.data);
					}
				});
			}
		}
	}
</script>

<style lang="less">
// 课程详情
.kcxq {
	height: 100upx;
	background-color: #4b89ff;
	text-align: center;
	line-height: 110upx;
	text {
		font-size: 32upx;
		font-weight: 700;
		color: #fff;
	}
}


// 背景图片
.beijing {
	height: 320upx;
	image {
		width: 100%;
		height: 320upx;
	}
}


// 课程名称
.course-name {
	padding: 0 20upx;
	padding-top: 40upx;
	background-color: #f6f6f6;
	text {
		font-size: 34upx;
		font-weight: 700;
		color: #191919;
	}
	view {
		margin-top: 10upx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.jianjie {
			width: 500upx;
			text {
				font-size: 24upx;
				font-weight: 400;
				color: #575757;
			}
		}
		.shoucang {
			margin-right: 35upx;
			display: flex;
			flex-direction: column;
			align-items: center;
			image {
				width: 38upx;
				height: 38upx;
			}
			text {
				font-size: 24upx;
				font-weight: 400;
				color: #aaa;
			}
		}
	}
	.price {
		height: 100upx;
		border-radius: 100upx;
		background-color: #fff;
		margin-top: 40upx;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0upx 6upx 10upx 2upx #dce5f6;
		text:nth-child(1) {
			font-size: 30upx;
			color: #ff6429;
			font-weight: 400;
		}
		text:nth-child(2) {
			font-size: 25upx;
			color: #999999;
			text-decoration: line-through;
			margin-left: 30upx;
			font-weight: 400;
		}
	}
}



// 课程介绍
.kcjs {
	padding: 0 20upx;
	margin-top: 54upx;
	margin-bottom: 150upx;
	&-title {
		font-size: 26upx;
		font-weight: 700;
		color: #131313;
	}
	.jiangshi {
		height: 140upx;
		margin-top: 24upx;
		background-color: #fff;
		border-radius: 20upx;
		display: flex;
		align-items: center;
		&-top {
			width: 78upx;
			height: 78upx;
			margin: 0;
			margin-left: 20upx;
		}
		&-bottom {
			display: flex;
			flex-direction: column;
			margin-left: 35upx;
			text:nth-child(1) {
				font-size: 30upx;
				color: #131313;
			}
			text:nth-child(2) {
				font-size: 23upx;
				color: #959595;
				margin-top: 10upx;
			}
		}
	}
	.kcjj {
		margin-top: 20upx;
		text:nth-child(1) {
			font-size: 26upx;
			font-weight: 700;
			color: #020202;
		}
		text:nth-child(2) {
			font-size: 26upx;
			color: #2d2d2d;
		}
	}
	image {
		width: 710upx;
		height: 405upx;
		margin-top: 50upx;
	}
}


.ljbm {
	width: 100%;
	height: 125upx;
	border-radius: 40upx 40upx 0 0;
	background-color: #fff;
	display: flex;
	align-items: center;
	justify-content: space-evenly;
	position: fixed;
	bottom: 0;
	text:nth-child(1) {
		font-size: 30upx;
		color: #ff6429;
	}
	text:nth-child(2) {
		width: 456upx;
		height: 87upx;
		border-radius: 87upx;
		background-image: linear-gradient(90deg, #4498ff, #3e5fff);
		font-size: 32upx;
		font-weight: 700;
		color: #fff;
		text-align: center;
		line-height: 87upx;
	}
}



</style>
